package com.loadmore.common.widget;

import android.content.Context;
import androidx.annotation.NonNull;
import android.view.View;

import com.loadmore.common.R;
import com.loadmore.common.base.BaseAdapter;
import com.loadmore.common.base.RVBaseHolder;
import com.loadmore.common.model.Category;

public class CardAdapter extends BaseAdapter {
    @Override
    public int getLayoutId() {
        return R.layout.card_layout;
    }

    public CardAdapter(Context context) {
        super(context);
    }

    private ClickListener clickListener;

    public void setClickListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }

    @Override
    public void onBindViewHolder(@NonNull final RVBaseHolder holder, int position) {
        Category category = (Category) getItem(position);
        holder.setText(R.id.name,category.name).setImage(context,R.id.card_icon,category.image);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (clickListener != null) {
                    clickListener.onClick(holder.getAdapterPosition());
                }
            }
        });
    }

    interface ClickListener {
        public void onClick(int position);
    }
}
